#include "MainWidget.h"

#include <QDebug>
#include <QProcess>
#include <QTimer>

QTimer timer;
QProcess process0, process1, process2, process3;
MainWidget::MainWidget()
{
    this->setMinimumSize(1024, 600);
    this->setSource(QUrl("qrc:/main.qml"));
    this->setResizeMode(QQuickWidget::ResizeMode::SizeRootObjectToView);
    this->engine()->rootContext()->setContextProperty("GET_ROOT", this);

    process0.setWorkingDirectory(QDir::currentPath() + "/Planning/HUSTCAD/bin71_x64");
    process0.setProgram("regsvr32");
    process0.setArguments(QStringList()<<QDir::currentPath() + "/Planning/HUSTCAD/bin71_x64/Inte3DActiveX.ocx");
    process0.start();
}

void MainWidget::quit()
{
    qApp->exit(0);
}

void MainWidget::startApp(int index)
{
    if(index == 0)
    {
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert("PATH", env.value(QString("Path;%1").arg(QDir::currentPath() + "/Planning/HUSTCAD/bin71_x64")));
        process1.setProcessEnvironment(env);
        process1.setWorkingDirectory(QDir::currentPath() + "/Planning/");
        connect(&process1, &QProcess::started, [=](){emit started();});
        process1.start(QDir::currentPath() + "/Planning/Planning.exe");

    }
    else if(index == 2)
    {
        process3.setWorkingDirectory(QDir::currentPath() + "/LoadModelTest/");
        connect(&process3, &QProcess::started, [=](){emit started();});
        process3.start(QDir::currentPath() + "/LoadModelTest/XRTest.exe");

    }
    else if(index == 1)
    {
        process2.setWorkingDirectory(QDir::currentPath() + "/TolAnalysis/");
        connect(&process2, &QProcess::started, [=](){emit started();});
        process2.start(QDir::currentPath() + "/TolAnalysis/UserInterface.exe");
    }
    else
    {

    }
}

